#!/bin/bash


for ((i=1;i<=10;i++))
do
name=vm$i
cores="1"
memory="16Gi"
cat <<EOF  | kubectl apply -f -
apiVersion: kubevirt.io/v1
kind: VirtualMachine
metadata:
  labels:
    kubevirt.io/vm: vm-centos7.5
  name: $name
spec:
  running: true
  template:
    metadata:
      labels:
        kubevirt.io/vm: vm-centos7.5
    spec:
      domain:
        cpu:
          cores: $cores
          sockets: 1
          threads: 1
        resources:
          overcommitGuestOverhead: true
          requests:
            cpu: "$cores"
            memory: $memory
#          limits:
#            cpu: 1000m
# 加了限制启动会很慢
#            memory: 1Gi
        devices:
          disks:
          - name: containerdisk
            disk:
              bus: virtio
          - name: emptydisk
            disk:
              bus: virtio
          - name: cloudinitdisk
            disk:
              bus: virtio
          interfaces:
          - name: default
            bridge: {}
      terminationGracePeriodSeconds: 0
      networks:
      - name: default
        pod: {}
      volumes:
      - name: containerdisk
        containerDisk:
          image: kubevirt:centos7.5
      - name: emptydisk
        emptyDisk:
          capacity: 100Gi
      - name: cloudinitdisk
        cloudInitNoCloud:
          userData: |
            #!/bin/sh
            echo 000000 | passwd --stdin root

EOF
done



echo "watch kubectl get pod,vmi"
